package servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import biz.AdminBiz;
import biz.impl.AdminBizImpl;
import entity.Admin;

@WebServlet("/AdminLoginServlet.html")
public class AdminLoginServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
	}
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String userName=request.getParameter("adminUsername");
		String password=request.getParameter("adminPassword");
		AdminBiz adminBiz = new AdminBizImpl();
		Admin admin=adminBiz.loginAdmin(userName, password);
		if(admin!=null){
			request.getSession().setAttribute("admin", admin);
			response.sendRedirect(request.getContextPath()+"/admin/AdminFoodServlet.html");
		}else{
			request.setAttribute("error", "用户名或密码有误");
			request.getRequestDispatcher("adminLogin.jsp").forward(request, response);
		}
	}

}
